package main.com.hushengjin.factory;

import main.com.hushengjin.model.Shape;
import main.com.hushengjin.model.impl.Circle;
import main.com.hushengjin.model.impl.Rectangle;
import main.com.hushengjin.model.impl.Square;

public class ShapeFactory {
    //使用getShape方法获取形状类型对象
    public Shape getShape(String shapeType) {
        if (shapeType == null || shapeType.length() <= 0) throw new IllegalArgumentException("unknown shape type: " + shapeType);
        shapeType = shapeType.toUpperCase();
        Shape shape;
        switch (shapeType) {
            case "CIRCLE":
                shape = new Circle();
                break;
            case "RECTANGLE":
                shape = new Rectangle();
                break;
            case "SQUARE":
                shape = new Square();
                break;
            default:
                throw new IllegalArgumentException("unknown shape type: " + shapeType);
        }
        return shape;
    }
}
